
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:oral_cloud/config/app_config.dart';
import 'package:oral_cloud/config/constant.dart';

import 'ButtonProgressIndicator.dart';

class GlobalAppBar {
  final String title;
  bool showUser;
  Widget widget;
  List<Widget> actions=[];
  GlobalAppBar(this.title,{this.widget});

  PreferredSizeWidget get appBar {
    if (widget != null) {
//      actions.add(Image.asset(ImageHelper.wrapAssets('person_center.png'),
////        width: ScreenUtil.getInstance().setWidth(55),
////        height: ScreenUtil.getInstance().setHeight(56),
////      ));
      actions.add(widget);
      actions.add(SizedBox(width: ScreenUtil.getInstance().setWidth(42),));
    }
    PreferredSizeWidget appbar;
    if (!AppConfig.isPad) {
      appbar = AppBar(
        brightness: Brightness.dark,
        actions: actions,
        iconTheme: IconThemeData(
          color: Colors.white, //change your color here
        ),
//      flexibleSpace: Container(
//        decoration: BoxDecoration(
//          gradient: LinearGradient(
//            colors: [Color(0xFF38ca95), Color(0xFF34afa7)],
//          ),
//        ),
//      ),
        title: Text(title, style: TextStyle(
            color: Colors.white,
            fontSize: FontSize.fontSizeXXL
        ),),
        centerTitle: true,);
    } else {
      appbar = PreferredSize(
        preferredSize: Size.fromHeight(ScreenUtil.getInstance().setHeight(122)),
        child: AppBar(
          actions: actions,
          iconTheme: IconThemeData(
            color: Colors.white, //change your color here
          ),
//      flexibleSpace: Container(
//        decoration: BoxDecoration(
//          gradient: LinearGradient(
//            colors: [Color(0xFF38ca95), Color(0xFF34afa7)],
//          ),
//        ),
//      ),
          title: Text(title, style: TextStyle(
              color: Colors.white,
              fontSize: FontSize.fontSizeXL
          ),),
          centerTitle: true,),
      );
    }
    return appbar;
  }


}

class RoundContainer extends StatelessWidget{
  final Widget child;

  RoundContainer({this.child});
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return ClipRRect(
      child: child,
      borderRadius: BorderRadius.circular(4),
    );
  }
}

class TypeText extends StatelessWidget{
  final String title;

  TypeText(this.title);
  @override
  Widget build(BuildContext context) {
    return Container(
      height: ScreenUtil.getInstance().setHeight(100),
      alignment: Alignment.center,
      child: Text(title,
        overflow: TextOverflow.ellipsis,
        maxLines: 1,
        style: TextStyle(
          color: Color(MYColors.textNormalColor),
          fontSize: FontSize.fontSizeL,

        ),
      ),
    );
  }
}


class NormalText extends StatelessWidget{
  final String title;

  NormalText(this.title);
  @override
  Widget build(BuildContext context) {
    return Text(title,
      overflow: TextOverflow.ellipsis,
      maxLines: 1,
      style: TextStyle(
        color: Color(MYColors.textNormalColor),
        fontSize: FontSize.fontSizeL,

      ),
    );
  }
}
class MultiNormalText extends StatelessWidget{
  final String title;

  MultiNormalText(this.title);
  @override
  Widget build(BuildContext context) {
    return Text(title,
      style: TextStyle(
        color: Color(MYColors.textNormalColor),
        fontSize: FontSize.fontSizeL,

      ),
    );
  }
}


/// 带分割线的Text

class UnderLineText extends StatelessWidget{
  final String title;
  double height;
  Color color;
  UnderLineText(this.title,{this.height,this.color:const Color(MYColors.textNormalColor)});

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      height: height,
      alignment: Alignment.centerLeft,
      decoration: BoxDecoration(
        border: Border(
          bottom: BorderSide(
            width: 0.5,
            color: Color(0xffe2ebf0),
          ),
        ),),
      child: Text(title,
    style: TextStyle(
    color: color,
    fontSize: FontSize.fontSizeL,
    )),
    );
  }

}

class CommonBtnWidget extends StatelessWidget {
  final String title;
  final GestureTapCallback onTap;
  final double width;
  final double height;
  final bool isLoading;

  CommonBtnWidget(this.title, {this.onTap, this.width, this.height, this.isLoading:false});

  @override
  Widget build(BuildContext context) {
    var color = Theme.of(context).primaryColor;
    return GestureDetector(
      onTap:onTap ,
      child: Container(
          alignment: Alignment.center,
          width: width,
          height:height,
          decoration: new BoxDecoration(
            color: color,
            //设置四周圆角 角度
            borderRadius: BorderRadius.all(Radius.circular(2.0)),
            //设置四周边框
        border: new Border.all(width: 1, color: color),
          ),
          child: isLoading?ButtonProgressIndicator(size: height-6,):Text(title,style: TextStyle(
              color: Colors.white,
              fontSize: FontSize.fontSizeL
          ),)

      ),
    );
  }
}

// Description：横线
class HorizontalLine extends StatelessWidget {
  final double dashedWidth;
  final double dashedHeight;
  final Color color;

  HorizontalLine({
    this.dashedHeight = 1,
    this.dashedWidth = double.infinity,
    this.color = const Color(0xFF555555),
  });

  @override
  Widget build(BuildContext context) {
    return Container(width: dashedWidth, height: dashedHeight, color: color);
  }
}

class CommonButtonWidget extends StatelessWidget {
  final Widget child;
  final VoidCallback onPressed;
  final double height;
  final double width;
  CommonButtonWidget({this.child, this.onPressed, this.height, this.width:double.infinity});

  @override
  Widget build(BuildContext context) {

    return Container(
      width: width,
      height:height ,
      child: CupertinoButton(
        padding: EdgeInsets.all(0),
        color: Color(MYColors.btnBgColor),
        disabledColor: Color(MYColors.btnBgDisabledColor),
        borderRadius: BorderRadius.circular(3),
        pressedOpacity: 0.5,
        child: child,
        onPressed: onPressed,
      ),
    );
  }
}